import Vue from "vue"
import vuex from "vuex"
Vue.use(vuex)

let storePlayList=[];
const value=JSON.parse(uni.getStorageSync("playList"));
if(value){
	storePlayList=value;
}


const store=new vuex.Store({
	actions:{
		
	},
	mutations:{
		getUser(state,data){
			const token=JSON.parse(uni.getStorageSync("token"));
			const profile=JSON.parse(uni.getStorageSync("profile"));
			const temp = {
				hasLogin: true,
				token: token,
				profile: profile
			};
			state.userInfo = temp;
			if(data){
				const detail={
					eventCount:data.eventCount,
					followends:data.followends,
					follows:data.follows,
					level:data.level
				};
				uni.setStorageSync("detail",JSON.stringify(detail));
			}
			state.detail=JSON.parse(uni.getStorageSync("detail"));
		},
		
		logoutClear(state){
			uni.removeStorageSync('token');
			uni.removeStorageSync('profile');
			const temp = {
				hasLogin: false,
				token: "",
				profile: {}
			};
			state.userInfo = temp;
			const detail={};
			state.detail = temp;
		},
		
		leavePage(state){
			let leaveTime=new Date().getTime();
			state.leaveTime=leaveTime;
		},
		
		setPlayList(state,data){
			if(data){
				uni.setStorageSync("playList",JSON.stringify(data))
			};
			state.playList=JSON.parse(uni.getStorageSync("playList"))
			
		},
	},
	state:{
		userInfo: {
			hasLogin: false,
		},
		detail:{},
		leaveTime:"",
		playList:storePlayList
		
	}
})
export default store